home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 November / Macworld (1999-11).dmg / Updaters / WhiteCap 3.0.4 / WhiteCap Source.sit / WhiteCap Source / Common / General Tools / Headers / EgThread.h < prev    next >
Text File  |  1999-07-13  |  2KB  |  58 lines

  1.  
  2. #ifndef _EGTHREAD_
  3. #define _EGTHREAD_
  4.  
  5. #include "XPtrList.h"
  6.  
  7.  
  8. class EgThread {
  9.     
  10.     private:
  11.         friend class EgThread;
  12.         static XPtrList                sThreadList;
  13.  
  14.         char                        mOwnedElsewhere;
  15.         char                        mStopped;    
  16.         unsigned long int            mResumeTime;
  17.         unsigned long int            mDelay;            
  18.     
  19.     protected:
  20.         unsigned long int            mLastExecuted;
  21.         
  22.         // Callback when this thread is stopped
  23.         virtual void                StopSelf();
  24.     
  25.     public:
  26.         
  27.         //    Post:    This thread is contstructed and SpendTime() will be called every
  28.         //            <inTimeDelay> milliseconds.  When the thread is stopped, it will later
  29.         //            be trash collected (and deleted) if <inOwnedElsewhere> is false.
  30.                                     EgThread( long inTimeDelay, int inOwnedElsewhere );
  31.  
  32.         virtual                     ~EgThread();
  33.         
  34.         //    Post:    SpendTime() is longer called and the StopSelf() callback is be called
  35.         //            and this thread will be deleted at a later time if this thread isn't owned elsewhere.
  36.         void                        Stop();
  37.         
  38.         //    Post:    Returns true if this thread had been terminated.
  39.         bool                        IsStopped()            { return mStopped;    }
  40.         
  41.         //     Post:    Will not get a SpendTime() until inSleepTime miliseconds from the present
  42.         void                        Sleep( long inSleepTime );    
  43.         
  44.         virtual void                Suspend();
  45.         virtual void                Resume();
  46.         
  47.         // Post:    Overide this to run one iteration of your thread. Upon entering, <mLastExecuted> will contain
  48.         //            the present time in milliseconds.
  49.         virtual void                SpendTime() = 0;
  50.         
  51.         // Post:    OS specific class must call DoThreads repeatedly with the current time (in milliseconds)
  52.         static void                    DoThreads();
  53.         
  54.         // Post:    Calling this will stop all running threads.  Typically used in low memory situations
  55.         static void                    StopAllThreads();
  56. };
  57.  
  58. #endif